<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class CourseVideo extends Model
{
    use HasFactory;

    protected $appends = [
        'status_text',
    ];

    protected $fillable = ['title','cover','course_id','video_id','clicks','set','try_see','status','sort'];

    const POSTONLY = ['title','cover','course_id','video_id','clicks','set','try_see','status','sort'];

    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    public function getStatusTextAttribute()
    {
        return $this->status == 1 ? '上架' : '下架';
    }

    public function video()
    {
        return $this->hasOne(Video::class,'id','video_id');
    }

}
